import * as actionType from "./actionType"
import {GetdotoSearch} from '../../http/dutoApi'
import {GetoverdueSearch} from '../../http/dutoApi'
import {CollectionSearch} from '../../http/dutoApi'

export const GetdotoSearchAction = (data) => ({
  type: actionType.DOTO_SEARCH,
  data,
})

// 即将到期搜索
export const GetdotoSearchAsyncAction = (obj) =>(dispatch) =>
  GetdotoSearch(obj)
    .then((res)=>{
      console.log('获取后端数据',res.data.data);
      dispatch(GetdotoSearchAction(res.data.data))
      // let key = 0
      console.log('搜索成功',res);
      return Promise.resolve('ok')
    })
    .catch((err)=>{
      console.log('搜索失败',err);
      return Promise.reject('fail')
  })

  //逾期搜索
  export const GetoverdueSearchAsyncAction = (obj) =>(dispatch) =>
  GetoverdueSearch(obj)
    .then((res)=>{
      console.log('获取后端数据',res.data.data);
      dispatch(GetdotoSearchAction(res.data.data))
      // let key = 0
      console.log('搜索成功',res);
      return Promise.resolve('ok')
    })
    .catch((err)=>{
      console.log('搜索失败',err);
      return Promise.reject('fail')
  })

  // 催款记录搜索
  export const CollectionSearchAsyncAction = (obj) =>(dispatch) =>
  CollectionSearch(obj)
    .then((res)=>{
      console.log('获取后端数据',res.data.data);
      dispatch(GetdotoSearchAction(res.data.data))
      // let key = 0
      console.log('搜索成功',res);
      return Promise.resolve('ok')
    })
    .catch((err)=>{
      console.log('搜索失败',err);
      return Promise.reject('fail')
  })
